<template>
  <div class="interfaces">
    <!-- 按钮 -->
    <div class="btns">
      <el-form size="small" inline style="text-align: right">
        <el-form-item label="名称">
          <el-input v-model="param.name"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" size="small" @click="loadInterfacess" icon="el-icon-search">搜索</el-button>
        </el-form-item>
        <el-button type="primary" size="small" @click="toAddHandler">下一页</el-button>
      </el-form>
      <div style="text-align: left">
      <el-button type="primary" size="small" @click="toAddHandler">新增</el-button>
      <el-button type="success" size="small" @click="downloadHandler">导出</el-button>
      </div>
    </div>
    <!-- /按钮 -->
    <!-- {{interfacess}} -->
    <!-- 表格 -->
    <el-table size="small" :data="interfacess">
      <el-table-column type="index" :index="1" label="序号"></el-table-column>
      <el-table-column label="名称" prop="name" align="center"></el-table-column>
      <el-table-column label="状态" prop="status" align="center"></el-table-column>
      <el-table-column label="url" prop="url" align="center"></el-table-column>
      <el-table-column label="limitTimes" prop="limitTimes" align="center"></el-table-column>
      <el-table-column label="用户姓名" prop="userName" align="center"></el-table-column>
      <el-table-column label="模块ID" prop="moduleId" align="center"></el-table-column>
      <el-table-column label="用户ID" prop="userId" align="center"></el-table-column>
      <el-table-column label="操作" width="144" align="center">
        <!-- 定制-插槽 -->
        <template slot-scope="scope">
          <el-button type="primary" icon="el-icon-edit" circle size="mini" @click="editHandler(scope.row)">修改</el-button>
          <el-button type="danger" icon="el-icon-delete" circle size="mini" @click="deleteHandler(scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- /表格 -->
  </div>
</template>
<script>
import {del, get,post} from '@/utils/request'
export default {
  // 页面数据
  data(){
    return {
      param: {
        name:""
      },
      interfacess:[]
    }
  },
  // 页面渲染的时候会调用的函数
  created(){
    this.loadInterfacess();
  },
  // 所有的方法
  methods:{
       downloadHandler(){
         window.location.href = "http://47.111.2.173:8888/interfaces/download?name="+this.param.name;
    },
    editHandler(row){
      this.$router.push({
        path: "/interfaces/create",
        query:row,
      });
    },

    deleteHandler(row){
       this.$confirm("此操作将永久删除该数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        let url = "http://47.111.2.173:8888/interfaces/deleteById";
        del(url, { id: row.id }).then((resp) => {
          this.$message({ type: "success", message: resp.message });
          this.loadInterfacess();
        });
      });
    },


    toAddHandler(){
      this.$router.push("/interfaces/create")
    },
    loadInterfacess(){
      let url = 'http://47.111.2.173:8888/interfaces/query'
      get(url,this.param).then((resp)=>{
        this.interfacess = resp.data;
      })
    }
  }
}
</script>
<style scoped>
.btns {
  margin-bottom: .5em;
}
</style>